#include <bits/stdc++.h>

#define N 10005
#define M 1000

using namespace std;

int p[N], a[N], b[N], sb[N], f[N][1005];

int main()
{
    int i, j, n, q, x;
    scanf("%d", &n);
    for (i = 1;i <= n;++i)scanf("%d %d %d", &p[i], &a[i], &b[i]);
    for (i = 1;i <= n;++i)sb[i] = sb[i - 1] + b[i];
    for (i = 0;i <= M;++i)f[n + 1][i] = i;
    for (i = n;i;--i)
        for (j = 0;j <= M;++j)
            if (p[i] >= j)f[i][j] = f[i + 1][j + a[i]];
            else f[i][j] = f[i + 1][max(j - b[i], 0)];
    scanf("%d", &q);
    while (q--) {
        scanf("%d", &x);
        int k = upper_bound(sb + 1, sb + n + 1, x - M) - sb;
        if (x <= M) printf("%d\n", f[1][x]);
        else if (k == n + 1) printf("%d\n", x - sb[n]);
        else printf("%d\n", f[k + 1][x - sb[k]]);
    }
    return 0;
}
